<template>
  <view class="mine-container" :style="{height: `${windowHeight}px`}">
    <!--顶部个人信息栏-->
    <view class="header-section">
      <view class="flex padding justify-between">
        <view class="flex align-center">
          <view v-if="!avatar" class="cu-avatar xl round bg-white">
            <view class="iconfont icon-people text-gray icon"></view>
          </view>
          <image v-if="avatar" @click="handleToAvatar" :src="avatar" class="cu-avatar xl round" mode="widthFix">
          </image>
          <view v-if="!name" @click="handleToLogin" class="login-tip">
            点击登录
          </view>
          <view v-if="name" @click="handleToInfo" class="user-info flex-direction">
            <view class="u_title">
              {{ name }}
            </view>
			<view class="u_title">
			  ID:{{ id }}
			</view>
          </view>
        </view>
        <view @click="handleToInfo" class="flex align-center">
          <text>个人信息</text>
          <view class="iconfont icon-right"></view>
        </view>
      </view>
	  <view class="barge">
		<view class="flex justify-between" style="border-bottom: 1rpx solid #E7001240;padding-bottom: 40rpx;">
			<view class="flex" style="align-items: center;">
				<view style="border-radius: 50rpx;background-color: #E70012; width: 8rpx; height: 34rpx;"></view>
				<view style="font-weight: 700;font-size: 40rpx;color: #E70012;line-height: 40rpx;margin-left: 4rpx;">我的徽章</view>
			</view>
			<view style="font-weight: 400;font-size: 28rpx;color: #565656;" @click="goBadge()" v-if="badgeList.length > 0">查看更多</view>
		</view>
		<view class="flex">
			<view class="icon" v-if="badgeList.length > 0" v-for="(item,index) in badgeList">
				<image class="icon-image" mode="aspectFill" :src="item.imageUrl"></image>
				<view class="icon-title" :style="{color:item.color}">{{item.name}}</view>
			</view>
			<view class="icon" style="width: 100%;margin-top: 20rpx;margin: bottom 10rpx;height: 104rpx;color: #565656;" v-if="badgeList.length == 0">
				<view>您还未获得徽章！</view>
			</view>
		</view>
	  </view>
	  <view class="flex justify-between">
	  		<image style="width: 336rpx; height: 146rpx;" mode="aspectFill" src="../../static/images/myShare.png" @click="goShare()"></image>
	  		<image style="width: 336rpx; height: 146rpx;" mode="aspectFill" src="../../static/images/mySign.png" @click="goSign()"></image>
	  </view>
    </view>

    <view class="content-section">
		<view class="section-item flex">
			<view class="flex align-center justify-center">
				<image style="width: 94rpx;height: 94rpx;" mode="aspectFill" src="../../static/images/phone.png"></image>
			</view>
			<view class="item-content">
				<view>
					客服电话：{{configInfo.phone}}
				</view>
				<view>
					工作时间：{{configInfo.workTime}}
				</view>
			</view>
		</view>
		<view class="section-item flex">
			<view class="flex align-center justify-center">
				<image style="width: 94rpx;height: 94rpx;" mode="aspectFill" src="../../static/images/email.png"></image>
			</view>
			<view class="item-content">
				<view class="">
					邮箱：{{configInfo.email}}
				</view>
				<view>
					可发送邮件至我们的邮箱内
				</view>
			</view>
		</view>
    </view>
  </view>
</template>

<script>
	import { getToken } from '../../utils/auth'
import { getConfigInfo,badge } from '@/api/system/pubulic'
  export default {
    data() {
      return {
        name: this.$store.state.user.name,
		id:this.$store.state.user.id,
		badgeList:[],
		configInfo:{
			phone:"400-123-4567",
			workTime:"8:00-9:00",
			email:"1111111@11.com"
		}
      }
    },
	created() {
		getConfigInfo().then((res)=>{
			this.configInfo = res.data
		});
	},
	onShow() {
		if(getToken()){
			badge().then((res)=>{
				this.badgeList = res.data;
			})
		}
		this.name = this.$store.state.user.name;
		this.id = this.$store.state.user.id;
	},
    computed: {
      avatar() {
        return this.$store.state.user.avatar
      },
      windowHeight() {
        return uni.getSystemInfoSync().windowHeight - 50
      }
    },
    methods: {
		goBadge(){
			uni.navigateTo({
				url:"/pages/mine/barrage"
			})
		},
      handleToInfo() {
        this.$tab.navigateTo('/pages/mine/info/index')
      },
      handleToEditInfo() {
        this.$tab.navigateTo('/pages/mine/info/edit')
      },
      handleToSetting() {
        this.$tab.navigateTo('/pages/mine/setting/index')
      },
      handleToLogin() {
        this.$tab.reLaunch('/pages/login')
      },
      handleToAvatar() {
        this.$tab.navigateTo('/pages/mine/avatar/index')
      },
     goShare(){
		 this.$tab.navigateTo('/pages/my/share')
	 },
     goSign(){
		 this.$tab.navigateTo('/pages/my/index')
	 }
    }
  }
</script>

<style lang="scss" scoped>
  page {
    background-color: #f5f6f7;
  }

  .mine-container {
    width: 100%;
    height: 100%;


    .header-section {
      padding: 30rpx;
      //background-color: #3c96f3;
	  background: linear-gradient(180deg,#E85142 0%,#E85142dd 60%, #F4F5F6);
      color: white;
		.barge{
			background: linear-gradient(90deg,#f9e5d1cc,#F9E9DAcc 50%, #F3C096cc);
			padding: 30rpx 20rpx 30rpx 40rpx;
			border-radius: 20rpx;
			margin-bottom: 30rpx;
		}
		.icon{
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			width: 25%;
			.icon-image{
				width: 104rpx;
				height: 104rpx;
				margin-top: 20rpx;
				margin-bottom: 10rpx;
			}
			.icon-title{
				font-weight: 400;
				font-size: 28rpx;
			}
		}
      .login-tip {
        font-size: 18px;
        margin-left: 10px;
      }

      .cu-avatar {
        border: 2px solid #eaeaea;

        .icon {
          font-size: 40px;
        }
      }

      .user-info {
        margin-left: 15px;

        .u_title {
          font-size: 18px;
          line-height: 30px;
        }
      }
    }

    .content-section {
      position: relative;
      //top: -50px;
		.section-item{
			margin: 20rpx 30rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			padding: 30rpx;
		}
		.item-content{
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			align-items: flex-start;
			font-size: 32rpx;
			color: #333333;
			margin-left: 18rpx;
		}
      .mine-actions {
        margin: 15px 15px;
        padding: 20px 0px;
        border-radius: 8px;
        background-color: white;

        .action-item {
          .icon {
            font-size: 28px;
          }

          .text {
            display: block;
            font-size: 13px;
            margin: 8px 0px;
          }
        }
      }
    }
  }
</style>
